#3 Use geom_violin to examine the wind speed and dew point by region
met_avg <-na.omit(met_avg)ggplot(met_avg, aes(x =1, y = wind.sp)) +geom_violin(aes(fill = region), scale ="width", width =0.8, na.rm =TRUE) +geom_violin(aes(x =2, y = dew.point, fill = region), scale ="width", width =0.8, na.rm =TRUE) +labs(x =NULL, y ="Value") +scale_x_continuous(breaks =c(1, 2), labels =c("Wind Speed", "Dew Point")) +facet_wrap(~region, nrow =1) +ggtitle("Wind Speed and Dew Point by Region")
It appears that wind speed and dew point have an inverse relationship. Dew points are high when wind speed is lower. It appears that in the southwest, there is a lot more dew overall compared to the other regions, having a large range.
#4 Use geom_jitter with stat_smooth to examine the association between dew point and wind speed by region
ggplot(met_avg, aes(x = dew.point, y = wind.sp, color = region, na.rm =TRUE)) +geom_jitter() +stat_smooth() +labs(x ="Dew Point", y ="Wind Speed") +ggtitle("Association Between Dew Point and Wind Speed by Region")
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
#5 Use geom_bar to create barplots of the weather stations by elevation category colored by region
ggplot(met_avg, aes(x = elev_cat, fill = region)) +geom_bar(position ="dodge", na.rm =TRUE) +scale_fill_brewer(palette ="PiYG") +labs(x ="Elevation Levels", y ="Count", fill ="Region") +ggtitle("Weather Stations by Elevation Levels and Region")
In the graph, we can see that in the northwest, it has a lot of weather stations at the lower elevation levels. At higher elevations, the northeast has a lot of weather stations but not as much as northwest at lower elevation. In both elevation levels, southeast has the least amount of weather stations.
#6 Use stat_summary to examine mean dew point and wind speed by region with standard deviation error bars
ggplot(met_avg, aes(x = region, y = dew.point)) +geom_point() +geom_point(aes(y = wind.sp), color ="blue") +stat_summary(fun.data ="mean_sdl",geom ="errorbar", ) +stat_summary(fun.data ="mean_sdl", geom ="errorbar",aes(y = wind.sp),color ="blue" ) +labs(x ="Region",y ="Mean Value",title ="Mean Dew Point and Wind Speed by Region with Error Bars" ) +theme_minimal()
Dew point is more spread across the values, with a large variance. Wind speed is more limited with a shorter range and has smaller variance in comparison. The only ones where wind speeds are within the range of dew points are in the southeast and southwest.
#7 Make a map showing the spatial trend in relative humidity in the US
library(leaflet)met_avg2 <- met[,.(rh, lat = lat, lon = lon), by=c("USAFID")]met_avg2 <- met_avg2[!is.na(rh)]rh.pal <-colorNumeric(c('blue','green', 'yellow', 'red'), domain = met_avg2$rh)rh.pal
function (x)
{
if (length(x) == 0 || all(is.na(x))) {
return(pf(x))
}
if (is.null(rng))
rng <- range(x, na.rm = TRUE)
rescaled <- scales::rescale(x, from = rng)
if (any(rescaled < 0 | rescaled > 1, na.rm = TRUE))
warning("Some values were outside the color scale and will be treated as NA")
if (reverse) {
rescaled <- 1 - rescaled
}
pf(rescaled)
}
<bytecode: 0x7fbc89d96df0>
<environment: 0x7fbc89d948b0>
attr(,"colorType")
[1] "numeric"
attr(,"colorArgs")
attr(,"colorArgs")$na.color
[1] "#808080"